package com.ruoyi.cat.service.impl;

import com.alipay.api.AlipayApiException;
import com.alipay.api.AlipayClient;
import com.alipay.api.domain.AlipayTradeAppPayModel;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import com.ruoyi.cat.domain.AlipayConfig;
import com.ruoyi.cat.domain.VO.OrderPaymentVO;
import com.ruoyi.cat.service.AlipayPaymentService;
import com.ruoyi.common.core.domain.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class AlipayPaymentServiceImpl implements AlipayPaymentService {

    @Autowired
    private AlipayConfig alipayConfig;
    @Autowired
    private AlipayClient alipayClient;

    @Override
    public AjaxResult orderPayment(OrderPaymentVO orderPaymentVO) {
        AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
        model.setSubject(body);
        model.setOutTradeNo(orderNo);
        model.setTotalAmount(String.valueOf(amount));
        model.setProductCode("QUICK_MSECURITY_PAY");
        model.setPassbackParams("公用回传参数，如果请求时传递了该参数，则返回给商户时会回传该参数");

        //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称：alipay.trade.app.pay
        AlipayTradeAppPayRequest ali_request = new AlipayTradeAppPayRequest();
        ali_request.setBizModel(model);
        ali_request.setNotifyUrl(alipayConfig.getNotifyUrl());// 回调地址
        AlipayTradeAppPayResponse ali_response = null;
        try {
            ali_response = alipayClient.sdkExecute(ali_request);
        } catch (AlipayApiException e) {
            throw new RuntimeException(e);
        }
        //就是orderString 可以直接给客户端请求，无需再做处理。
       // return ali_response.getBody();
        return null;
    }
}
